{{define "org/list.html"}}

<!DOCTYPE html>
<html>
	<head>
        {{template "header"}}
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="/welcome">首页</a>
        <a href="/admin/org/list">机构管理</a>
        <a><cite>机构列表</cite></a>
      </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="weadmin-body">
			<div class="layui-btn-container">
				<button class="fr layui-btn" onclick="WeAdminEdit('添加机构','/admin/org/add','addorgLayer',720,460)"><i class="layui-icon"></i>添加</button>
			</div>
			<table class="layui-table" lay-filter="treeTable" id="treeTable"></table>
		</div>
		<div id="_flashmsg_" style="display: none;">{{range .flashmsg}}{{.}}{{end}}</div>
    </body>

	{{template "jsfile"}}
	<!-- 操作列 -->
	<script type="text/html" id="org-op">
		<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
		<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
	<script type="text/javascript">
		var treeJsonData = JSON.parse('{{.dataJson}}');
		function orgRefreshForm(){
			location.replace(location.href);
		}

		layui.config({
		  base: '/static/js/'
		}).use('treetable');
		layui.use(['treetable','jquery','table','element', 'admin', 'carousel'], function(){
			var treetable = layui.treetable,
				element = layui.element,
				$ = layui.jquery,
				carousel = layui.carousel,
				table = layui.table,
				admin = layui.admin;

			//弹出Flash信息
			$(document).ready(function(){
				msg = $("#_flashmsg_").text()
				if(msg){
					layer.msg(msg, {time:3*1000,icon: 1});
				}
			});

			//渲染表格树
			treetable.render({
				treeColIndex: 1,
				treeSpid: 0,
				treeIdName: 'Id',
				treePidName: 'ParentId',
				elem: '#treeTable',
				data: treeJsonData,
				page: false,
				cols: [[
					{type: 'numbers'},
					{field: 'Name', minWidth: 200, title: '机构名称'},
					{field: 'Sortnum', width: 100, align: 'center', title: '排序号'},
					{templet: '#org-op', width: 180, align: 'center', title: '操作'},
				]],
			});

			//表格操作列事件监听
			table.on('tool(treeTable)', function(obj){
				var data = obj.data; //获得当前行数据
				var layEvent = obj.event;
				var tr = obj.tr;

				if(layEvent === 'detail'){
					WeAdminShow('详情','/admin/org/detail/'+data.Id,720,400);
				} else if(layEvent === 'del'){
					ajaxDelete('/admin/org/del/'+data.Id,function(){location.replace(location.href);});
				} else if(layEvent === 'edit'){
					WeAdminShow('编辑','/admin/org/edit/'+data.Id,820,440);
				}
			});
		});
	</script>

</html>
{{end}}